/************************************
*  Copyright (C) 2010 Julien MOTTIN.
*  Contact: julien.mottin@gueydan.eu
*
*  This file is part of Gueydan.
*
*  Gueydan is free software: you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  Gueydan is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with Gueydan.  If not, see <http://www.gnu.org/licenses/>.
*
*************************************/
#ifndef WEIGHT_H
#define WEIGHT_H

// Weight coeffs constants
const static double WCoeffKilogram  = 1.0;
const static double WCoeffGram      = 0.001;
const static double WCoeffOunce     = 0.0283495231;
const static double WCoeffPound     = 0.45359237;

// Handled Units
enum WeightUnit
{
    Kilogram = 0,
    Gram,
    Ounce,
    Pound
};

class QString;

class Weight
{
public:

    // Standard POD class
    Weight(const double iWeight = 0.0, const WeightUnit iUnit=Kilogram);
    Weight(const Weight &iW);
    Weight & operator=(const Weight &iW);
    ~Weight();

    // Operators
    bool operator==(const Weight &iW) const;
    bool operator!=(const Weight &iW) const;
    const Weight operator+(const Weight &iW) const;
    const Weight operator-(const Weight &iW) const;
    bool operator<(const Weight &iW) const;
    bool operator<=(const Weight &iW) const;
    bool operator>(const Weight &iW) const;
    bool operator>=(const Weight &iW) const;

    // Converter
    double Value(const WeightUnit iUnit=Kilogram) const;
    void FromString(const QString &iString, bool *OK=0);

    // Get GUI Value
    void GUIValue(double &oVal, QString &oUnit) const;

private:

    double Compare(const Weight &iW) const;

    // Internal data
    double _Value;  // in Kilogram
    WeightUnit _GUIUnit;
};

#endif // WEIGHT_H
